<!DOCTYPE html>
<html>

<head>
  <title>
    <%= title %>
  </title>
  <link rel='stylesheet' href='/stylesheets/style.css' />
</head>

<body>
  <script>
    
    function refreshImage(imgElement, imgURL) {
      // create a new timestamp 
      var xhr = new XMLHttpRequest();
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          imgURL = xhr.response;
          var timestamp = new Date().getTime();
          var el = document.getElementById(imgElement);
          var queryString = "?t=" + timestamp;
          el.src = imgURL + queryString;
        }
      }
      xhr.open('get', '/screenshot', true);
      xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
      xhr.send();

    }

  </script>
  <!-- <h1>
    <%= title %>
  </h1> -->
  <input type=button onClick="refreshImage('testimg', './images/test.jpg')" ; value='Recapture'>
  </p>
  <img id="testimg" src="<%= imageURL %>" style="height:auto;max-width:100%;">
</body>

</html>